<template>
  <div class="manage">
    <el-dialog
      :visible.sync="isShow"
      :title="operateType === 'add' ? '新增用户' : '更新用户'"
    >
      <CommonForm :formLabel="operateFromLabel" :form="operateFrom">
      </CommonForm>
      <div slot="footer" class="dialog-footer">
        <el-button @click="isShow = false">取 消</el-button>
        <el-button type="primary" @click="confirm = false">确 定</el-button>
      </div>
    </el-dialog>
    <div class="header">
      <el-button type="primary" icon="el-icon-circle-plus"> 新增</el-button>
      <CommonForm inline :formLabel="formLabel" :form="searchForm">
        <el-button type="primary" icon="el-icon-search"> 搜索</el-button>
      </CommonForm>
    </div>
    <CommonTable
      :tableData="tableData"
      :tableLabel="tableLabel"
      :config="config"
      @current-change="getList"
      @edit="editCsstaffwage"
      @del="delCsstaffwage"
    ></CommonTable>
  </div>
</template>

<script>
import CommonForm from "@/layout/CommonForm.vue";
import CommonTable from "@/layout/CommonTable.vue";
export default {
  components: {
    CommonForm,
    CommonTable
  },
  data() {
    return {
      isShow: false,
      operateType: "add",
      operateFrom: {
        name: "",
        addr: "",
        age: "",
		number: "",
        birth: "",
        sex: ""
      },
      operateFromLabel: [
        {
          model: "name",
          label: "姓名"
        },
        
        {
          model: "sex",
          label: "性别",
          type: "select",
          opts: [
            {
              label: "男",
              value: 1
            },
            {
              label: "女",
              value: 0
            }
          ]
        },
		{
		  model: "age",
		  label: "总工资"
		},
		{
		  model: "number",
		  label: "电话号码"
		}
      ],
      searchForm: {
        keyword: ""
      },
      formLabel: [
        {
          model: "keyword",
          label: ""
        }
      ],
      tableData: [],
      tableLabel: [
        {
          prop: "name",
          label: "姓名"
        },
        
        {
          prop: "sexLabel",
          label: "性别"
        },
		{
		  prop: "age",
		  label: "总工资"
		},
		{
		  prop: "number",
		  label: "电话号码",
		  width: 550
		}
      ],
      config: {
        page: 1,
        total: 30,
        loading: false
      }
    };
  },
  methods: {
    //无误获取参数
    getList() {
      this.config.loading = true;
      this.$http
        .get("http://localhost:9527/csstaffwage/get", { page: this.config.page })
        .then(res => {
          console.log(res.data); //调试看数据是否获取到
          this.tableData = res.data.list.map(item => {
            item.sexLabel = item.sex === 0 ? "女" : "男";
            return item;
          });
          this.config.total = res.data.count;
          this.config.loading = false;
        });
    },
    editCsstaffwage(row) {
      this.operateType = "edit";
      this.isShow = true;
      console.log(row);
      this.operateFrom = row;
    },
    confirm() {
      if (this.operateType === "edit") {
        this.$http
          .get("http://localhost:9527/csstaffwage/update", this.operateFrom)
          .then(res => {
            console.log(res.data);
            this.isShow = false;
            this.getList(); //编辑成功后需要重新刷新用户信息
          });
      }
    },
    delCsstaffwage(row) {
      this.$confirm("此操作将永久删除该文件, 是否继续?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning"
      })
        .then(() => {
          let id = row.id;
          this.$http
            .get("http://localhost:9527/csstaffwage/delete", {
              params: {
                id
              }
            })
            .then(res => {
              console.log(res.data);
              this.$message({
                type: "success",
                message: "删除成功!"
              });
            });
        })
        .catch(() => {
          this.$message({
            type: "info",
            message: "已取消删除"
          });
        });
    }
  },

  created() {
    //创建将数据请求发出
    this.getList();
  },
  name: "Csstaffwage"
};
</script>

<style lang="scss" scoped>
@import "~@/styles/manage.scss";
</style>
